﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Xml.Linq;

    using Csla;

    using MarketPulse.BusinessLogic.Core;

#endregion

namespace MarketPulse.Reporting.Core
{
    /// <summary>
    /// This class represents a read only reporting Question object.
    /// </summary>
    [Serializable]
    public class ReportingQuestionInfo : MarketPulseReadOnlyBase<ReportingQuestionInfo>
    {

        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private ReportingQuestionInfo()
            {
            }

        #endregion

        #region Methods

            /// <summary>
            /// Check whether this QuestionInfo object contains a specific Reference.
            /// </summary>
            /// <param name="referenceKey"></param>
            /// <returns></returns>
            public bool HasReference(string referenceKey)
            {
                return References.Contains(referenceKey);
            }

        #endregion

        #region Properties


            /// <summary>
            /// The primary key of this question in the database. (Unique identifier for ranking)
            /// </summary>
            public static PropertyInfo<long> IDProperty = RegisterProperty<long>(p => p.ID);
            /// <summary>
            /// The primary key of this question in the database. (Unique identifier for ranking)
            /// </summary>
            public long ID
            {
                get { return GetProperty(IDProperty); }
            }

            /// <summary>
            /// A list of special references/attribute for this question.
            /// </summary>
            public static PropertyInfo<List<string>> ReferencesProperty = RegisterProperty<List<string>>(p => p.References);
            public List<string> References
            {
                get { return GetProperty(ReferencesProperty); }
            }

            /// <summary>
            /// The GUID of the Client this question belongs to.
            /// </summary>
            public static PropertyInfo<Nullable<Guid>> ClientGUIDProperty = RegisterProperty<Nullable<Guid>>(p => p.ClientGUID);
            public Nullable<Guid> ClientGUID
            {
                get { return GetProperty(ClientGUIDProperty); }
            }

            /// <summary>
            /// The GUID of the visit this question belongs to.
            /// </summary>
            public static PropertyInfo<Nullable<Guid>> VisitGUIDProperty = RegisterProperty<Nullable<Guid>>(p => p.VisitGUID);
            public Nullable<Guid> VisitGUID
            {
                get { return GetProperty(VisitGUIDProperty); }
            }

            /// <summary>
            /// The GUID of the category that this question belongs to.
            /// </summary>
            public static PropertyInfo<Nullable<Guid>> CategoryGUIDProperty = RegisterProperty<Nullable<Guid>>(p => p.CategoryGUID);
            public Nullable<Guid> CategoryGUID
            {
                get { return GetProperty(CategoryGUIDProperty); }
            }

            /// <summary>
            /// The order in the category to display this question in.
            /// </summary>
            public static PropertyInfo<int> CategoryOrderProperty = RegisterProperty<int>(p => p.CategoryOrder);
            public Nullable<int> CategoryOrder
            {
                get { return GetProperty(CategoryOrderProperty); }
            }

            /// <summary>
            /// The category title for the category this question belongs to.
            /// </summary>
            public static PropertyInfo<string> CategoryTitleProperty = RegisterProperty<string>(p => p.CategoryTitle);
            public string CategoryTitle
            {
                get { return GetProperty(CategoryTitleProperty); }
            }

            /// <summary>
            /// The display number for this question.
            /// </summary>
            public static PropertyInfo<string> DisplayNumberProperty = RegisterProperty<string>(p => p.DisplayNumber);
            public string DisplayNumber
            {
                get { return GetProperty(DisplayNumberProperty); }
            }

            /// <summary>
            /// The non-displayed question number.
            /// </summary>
            public static PropertyInfo<string> NumberProperty = RegisterProperty<string>(p => p.Number);
            public string Number
            {
                get { return GetProperty(NumberProperty); }
            }

            /// <summary>
            /// The category title for the category this question belongs to.
            /// </summary>
            public static PropertyInfo<XElement> TextProperty = RegisterProperty<XElement>(p => p.Text);
            public XElement Text
            {
                get { return GetProperty(TextProperty); }
            }

            /// <summary>
            /// The type of question this is.
            /// </summary>
            public static PropertyInfo<string> TypeProperty = RegisterProperty<string>(p => p.Type);
            public string Type
            {
                get { return GetProperty(TypeProperty); }
            }

            /// <summary>
            /// The standard text for this question.
            /// </summary>
            public static PropertyInfo<XElement> StandardProperty = RegisterProperty<XElement>(p => p.Standard);
            public XElement Standard
            {
                get { return GetProperty(StandardProperty); }
            }

            /// <summary>
            /// The shopper note for this question.
            /// </summary>
            public static PropertyInfo<XElement> ShopperNoteProperty = RegisterProperty<XElement>(p => p.ShopperNote);
            public XElement ShopperNote
            {
                get { return GetProperty(ShopperNoteProperty); }
            }

            /// <summary>
            /// The QA note for this question.
            /// </summary>
            public static PropertyInfo<XElement> QANoteProperty = RegisterProperty<XElement>(p => p.QANote);
            public XElement QANote
            {
                get { return GetProperty(QANoteProperty); }
            }

            /// <summary>
            /// The possible score for this question.
            /// </summary>
            public static PropertyInfo<int> PossibleScoreProperty = RegisterProperty<int>(p => p.PossibleScore);
            public int PossibleScore
            {
                get { return GetProperty(PossibleScoreProperty); }
            }

            /// <summary>
            /// The actual score for this question.
            /// </summary>
            public static PropertyInfo<int> ActualScoreProperty = RegisterProperty<int>(p => p.ActualScore);
            public int ActualScore
            {
                get { return GetProperty(ActualScoreProperty); }
            }

            /// <summary>
            /// The time this question was transferred into the reporting database.
            /// </summary>
            public static PropertyInfo<SmartDate> TransferDateTimeProperty = RegisterProperty<SmartDate>(p => p.TransferDateTime);
            public SmartDate TransferDateTime
            {
                get { return GetProperty(TransferDateTimeProperty); }
            }

            /// <summary>
            /// A list of ReportingAnswers for this question.
            /// </summary>
            public static PropertyInfo<ReportingAnswerInfoList> ReportingAnswersProperty = RegisterProperty<ReportingAnswerInfoList>(p => p.Answers);
            public ReportingAnswerInfoList Answers
            {
                get
                {
                    if (!FieldManager.FieldExists(ReportingAnswersProperty))
                    {
                        LoadProperty(ReportingAnswersProperty, ReportingAnswerInfoList.GetByClientGUIDAndQuestionID(ClientGUID.Value, ID));
                        OnPropertyChanged(ReportingAnswersProperty);
                    }
                    return ReadProperty(ReportingAnswersProperty);
                }
            }

        #endregion

    }
}